package jp.ac.u_tokyo.dch.model;

import java.util.Stack;

public class ModoruBean {


	private Stack<String> urlStack = null;
	private Stack<String> paramStack = null;

	public ModoruBean() {

		urlStack = new Stack<String>();
		paramStack = new Stack<String>();
	}

	public void clear() {
		urlStack.clear();
		paramStack.clear();
	}

	public void push(String url, String param) {

		duplicateDel(url, param);
		urlStack.push(url);
		paramStack.push(param);

	}


	public String modoruUrl() {

		String url = urlStack.pop();
		String param = paramStack.pop();

		return url + "?" + param;
	}


	private void duplicateDel(String url, String param) {

		int check = -1;

		for (int i = 0; i < urlStack.size(); i++) {

			if (paramStack.get(i).equals(param)) {
				check = i;
				break;
			}
		}

		if (check >= 0) {

			while (check > -1) {
				urlStack.remove(check);
				paramStack.remove(check);
				--check;
			}
		}

	}

}
